# # 示例1：显示For循环的进度
# for($i = 1; $i -le 100; $i++){
#     Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i
#     Start-Sleep -Milliseconds 250
# }

# # 示例2：显示嵌套For循环的进度
# $PSStyle.Progress.View = 'Classic'

# for($I = 0; $I -lt 10; $I++){
#     $OuterLoopProgressParameters = @{
#         Activity = 'Updating'
#         Status = 'Progress->'
#         PercentComplete = $I * 10
#         CurrentOperation = 'OuterLoop'
#     }
#     Write-Progress @OuterLoopProgressParameters
#     for($j = 1; $j -lt 101; $j++){
#         $InnerLoopProgressParameters = @{
#             ID = 1
#             Activity = 'Updating'
#             Status = 'Progress'
#             PercentComplete = $j
#             CurrentOperation = 'InnerLoop'
#         }
#         Write-Progress @InnerLoopProgressParameters
#         Start-Sleep -Milliseconds 25
#     }
# }

# # 示例3：搜索字符串时显示进度
# # Use Get-WinEvent to get the events in the System log and store them in the $Events variable.
# $Events = Get-WinEvent -LogName System
# # Pipe the events to the ForEach-Object cmdlet.
# $Events | ForEach-Object -Begin{
#     # In the Begin block, use Clear-Host to clear the screen.
#     Clear-Host
#     # Set the $i counter variable to zero.
#     $i = 0
#     # Set the $out variable to a empty string.
#     $out = ""
# } -Process{
#     # In the Process script block search the message property of each incoming object for "bios".
#     if($_.message -like "*bios*"){
#         # Append the matching message to the out variable.
#         $out = $out + $_.Message
#     }
#     # Increment the $i counter variable which is used to create the progress bar.
#     $i = $i + 1
#     # Determine the completion percentage
#     $Completed = ($i/$Events.count*100)
#     # Use Write-Progress to output a progress bar.
#     # The Activity and Status parameters create the first and second lines of the progress bar
#     # heading, respectively.
#     Write-Progress -Activity "Searching Events" -Status "Progress:" -PercentComplete $Completed
# } -End{
#     # Display the matching messsage using the out variable.
#     $out
# }

# 示例4：显示嵌套进程每个级别的进度
$PSStyle.Progress.View = 'Classic'

foreach($i in 1..10){
    Write-Progress -Id 0 "Step $i"
    foreach($j in 1..10){
        Write-Progress -Id 1 -ParentId 0 "Step $i - Substep $j"
        foreach($k in 1..10){
            Write-Progress -Id 2 -ParentId 1 "Step $i - Substep $j - iteration $k"
            Start-Sleep -Milliseconds 150
        }
    }

}